const { Controller } = require('ee-core');
const log = require('ee-core/log');
class BaseController extends Controller{
    constructor(ctx) {
        super(ctx);
        this.log = log;
        this.init();
    }

    init(){

    }

    success(message = null,  data = {}, code = 200){
        if(typeof message !== "string"){
            data = message
            message = null
        }
        return {
            'success' : true,
            'message' : message != null ? message : '响应成功!',
            'code'    : code,
            'data'    : data,
        }
    }

    error(message = '', code = 500, data = {}){
        return {
            'success' : false,
            'message' : message != null ? message : '响应错误',
            'code'    : code,
            'data'    : data,
        }
    }


    static toString(){
        return "class [" + this.name + "]"
    }
}

module.exports = BaseController;